//    Copyright (C) Kherty.  All rights reserved.
using System;
using OpenLS.Core.Serialization;

namespace OpenLS.Spreadsheet.Data
{
    public class DatabaseConnection: DataConnection
    {
        private string _connection;

        public string Connection
        {
            get { return _connection; }
            set { _connection = value; }
        }

        private string command;

        public string Command
        {
            get { return command; }
            set { command = value; }
        }
        private string _serverCommand;

        public string ServerCommand
        {
            get { return _serverCommand; }
            set { _serverCommand = value; }
        }
        private int commandType = 2;

        public int CommandType
        {
            get { return commandType; }
            set { commandType = value; }
        }


        internal override void  ReadProperties(ReadContext context)
{
 	        using (ReadContext c = context.Read("dbPr"))
            {
                Connection = c.GetString("connection");
                Command = c.GetOptionalString("command");
                ServerCommand = c.GetOptionalString("serverCommand");
                CommandType = c.GetOptionalInteger("commandType", 2);

            }
        }

        internal override void  WriteProperties(WriteContext context)
{
 	        using (WriteContext c = context.Write("dbPr"))
            {
                c.SetString("connection", Connection);
                c.SetOptionalString("command", Command);
                c.SetOptionalString("serverCommand", ServerCommand);
                c.SetOptionalInteger("commandType", CommandType, 2);

            }
        }
        internal override void SetTypeIfNecessary()
        {
            if (Type == DataConnectionType.Unknown)
                throw new NotImplementedException();
        }
        internal override void Initialize()
        {
        }


    }

}
